
<div class="layui-card-header">用户角色</div>
<div class="layui-card-body layui-text layadmin-about">
    <script type="text/html" template>
        <p>当前角色：{$roles[$currentRole]}</p>
        <p>切换角色：</p>
    </script>
    <div class="layui-btn-container">
        {volist name="roles" id="vo"}
            <button date-role="{$key}" class="change-role layui-btn {if $currentRole == $key}layui-btn-disabled{/if}">{$vo}</button>
        {/volist}
    </div>
</div>

<hr>
<div class="layadmin-menu-list">
    <div class="layui-card-header">
        <a href="javascript:;" class="logout">
            <i class="layui-icon layui-icon-close"></i>
            退出
        </a>
    </div>
</div>

<script>
    layui.use(['jquery'], function () {
        var $ = layui.$;

        //监听提交
        $('.change-role').on('click', function () {
            if ($(this).hasClass('layui-btn-disabled')) {
                return false;
            }
            var id = $(this).attr('date-role');
            $.post("{:url('admin/index/changeRole')}", {id: id}, function (res) {
                if (res.code === 1) {
                    layer.msg(res.msg);
                    setTimeout(function () {
                        $(location).attr('href', res.url);
                    }, 1000);
                } else {
                    layer.msg(res.msg);
                }
            }, 'json');
        });

        $('.logout').on('click', function () {
            $.post("{:url('admin/login/logout')}", function (res) {
                if (res.code === 1) {
                    layer.msg(res.msg);
                    setTimeout(function () {
                        $(location).attr('href', res.url);
                    }, 1000);
                } else {
                    layer.msg(res.msg);
                }
            }, 'json');
        });
    });
</script>